package br.com.almanach.jsf.converter;

import br.com.almanach.dominio.cadastro.Musica;
import br.com.almanach.negocio.cadastro.MusicaNegocio;
import javax.ejb.EJB;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

public class MusicaConverter implements Converter {

    @EJB
    private MusicaNegocio musicaNegocio;

    public Object getAsObject(FacesContext fc, UIComponent uic, String string) {
        if (string.trim().equals("")) {
            return null;
        } else {
            Integer id = new Integer(string);
            Musica musica = musicaNegocio.buscar(id);
            return musica;
        }
    }

    public String getAsString(FacesContext fc, UIComponent uic, Object object) {
        if (object == null) {
            return null;
        } else {
            return String.valueOf(((Musica) object).getId());
        }
    }

    public void setMusicaNegocio(MusicaNegocio musicaNegocio) {
        this.musicaNegocio = musicaNegocio;
    }

}